Skip to content

Validation for using the same service-name for different resources#1673

Merged
vkalapov merged 4 commits into
cloudfoundry:masterfrom
karrgov:service_name_duplicating_warning
Aug 1, 2025
Merged

Validation for using the same service-name for different resources#1673
vkalapov merged 4 commits into
cloudfoundry:masterfrom
karrgov:service_name_duplicating_warning

Conversation

@karrgov

@karrgov karrgov commented Jul 29, 2025

Copy link
Copy Markdown
Contributor

LMCROSSITXSADEPLOY-1661

@linux-foundation-easycla

linux-foundation-easycla Bot commented Jul 29, 2025

Copy link
Copy Markdown

CLA Signed

The committers listed above are authorized under a signed CLA.

public static final String SERVICE_INSTANCE_0_PLAN_UPDATE_FAILED_IGNORING_FAILURE = "Service instance: \"{0}\" plan update failed, ignoring failure...";
public static final String SERVICE_INSTANCE_0_PARAMETERS_UPDATE_FAILED_IGNORING_FAILURE = "Service instance: \"{0}\" parameters update failed, ignoring failure...";
public static final String SERVICE_INSTANCE_0_TAGS_UPDATE_FAILED_IGNORING_FAILURE = "Service instance: \"{0}\" tags update failed, ignoring failure...";
public static final String ONLY_FIRST_SERVICE_WILL_BE_CREATED = "[WARNING] Only the first service will be created because provided 'service-name' fields are duplicated! All other services with the same 'service-name' will be ignored!";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the '[WARNING]' text consistent with any other message?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't actually - just made more sense to me - but will make it like the others, fixed

.collect(Collectors.toSet());
if (resolvedServiceInstancesNames.size() != resolvedServiceInstancesNamesWithoutDuplicates.size()) {
getStepLogger().warn(
Messages.ONLY_FIRST_SERVICE_WILL_BE_CREATED);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it makes more to sense to actually print out the specific duplicated service names instead of the generic warning

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

context.setVariable(Variables.SERVICES_TO_CREATE_COUNT, servicesToCreate.size());
}

private void checkForDuplicatedServiceNameFields(List<CloudServiceInstanceExtended> resolvedServiceInstances) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is only in the 'batchedServices...' step - is there an alternative flow in the diagram that doesn't split the service in batches and will it not validate in that case?

ikasarov
ikasarov previously approved these changes Jul 29, 2025
@karrgov karrgov force-pushed the service_name_duplicating_warning branch from c1a1d01 to 9e8348b Compare July 29, 2025 13:54
@karrgov karrgov force-pushed the service_name_duplicating_warning branch 3 times, most recently from ffec30f to 289b9c2 Compare July 29, 2025 14:11
public static final String SERVICE_INSTANCE_0_PLAN_UPDATE_FAILED_IGNORING_FAILURE = "Service instance: \"{0}\" plan update failed, ignoring failure...";
public static final String SERVICE_INSTANCE_0_PARAMETERS_UPDATE_FAILED_IGNORING_FAILURE = "Service instance: \"{0}\" parameters update failed, ignoring failure...";
public static final String SERVICE_INSTANCE_0_TAGS_UPDATE_FAILED_IGNORING_FAILURE = "Service instance: \"{0}\" tags update failed, ignoring failure...";
public static final String ONLY_FIRST_SERVICE_WILL_BE_CREATED = "Only the first service will be created because provided 'service-name' fields are duplicated! All other services with the same 'service-name' will be ignored! Duplicated names: ";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small typo:
".. created because the provided 'service-name' .."

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed!

List<String> duplicatedNames = getDuplicatedNames(resolvedServiceInstancesNames);
if (!duplicatedNames.isEmpty()) {
getStepLogger().warn(
Messages.ONLY_FIRST_SERVICE_WILL_BE_CREATED + String.join(" ", duplicatedNames));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using the string concatenation with the + operator, for the message, and instead use placeholders {0}.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed!

List<String> duplicatedNames = new ArrayList<>();
Map<String, Integer> frequencyOfNamesMap = new HashMap<>();
for (String name : resolvedServiceInstancesNames) {
frequencyOfNamesMap.put(name, frequencyOfNamesMap.getOrDefault(name, 0) + 1);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line could be replaced by frequencyOfNamesMap.merge(name, 1, Integer::sum);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, thank you for the suggestion!

@karrgov karrgov force-pushed the service_name_duplicating_warning branch from 56242a9 to 5a045a6 Compare July 30, 2025 07:48
@vkalapov vkalapov merged commit 4cb6d87 into cloudfoundry:master Aug 1, 2025
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants